package com.maisha.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {

	
	/** md5 加密字符串
	 * @param content
	 * @return
	 */
	public static String getMD5Result(String content){
		String result=null;
		try {
			char hexDigits[] = { '0', '1', '2', '3', '4',
                    '5', '6', '7', '8', '9',
                    'A', 'B', 'C', 'D', 'E', 'F' };
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] input = content.getBytes();
			byte[] mdout = md.digest(input);
			int j = mdout.length;
			char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = mdout[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            result =  new String(str);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static void main(String[] args){
		System.out.println(MD5Utils.getMD5Result("123"));
	}
	
}
